package de.stefanocke.roo.wicket.form.formfields;

import java.util.List;

import org.springframework.roo.classpath.details.ConstructorMetadata;
import org.springframework.roo.model.JavaType;

import de.stefanocke.roo.wicket.MidUtils;
import de.stefanocke.roo.wicket.base.BeanPropertiesAwareItdMetadataBase;
import de.stefanocke.roo.wicket.base.ModelClassAwareMetadataCreationParams;
import de.stefanocke.roo.wicket.form.FormComponentMetadata;
import de.stefanocke.roo.wicket.model.BeanPropertyMetadataWithDetails;

/**

 */
public class FormFieldsMetadata extends BeanPropertiesAwareItdMetadataBase<FormFieldsAnnotationValues, FormComponentMetadata> implements
		FormComponentMetadata {
	public static final MidUtils midUtils = MidUtils.get(FormFieldsMetadata.class);

	public FormFieldsMetadata(ModelClassAwareMetadataCreationParams<FormFieldsAnnotationValues> cmcp,
			List<BeanPropertyMetadataWithDetails<FormComponentMetadata>> propertiesForScaffolding) {
		super(cmcp, new FormFieldsItdBuilder(), propertiesForScaffolding);
		buildItdTypeDetails();

	}
	
	@Override
	public List<? extends ConstructorMetadata> getConstructors() {
		return getMemberHoldingTypeDetails().getDeclaredConstructors();
	}
	
	@Override
	public boolean needsDecoration() {
		// Wants to be wrapped in a ComplexFormField decorator...
		return true;
	}
	

//	/**
//	 * {@inheritDoc}
//	 */
//	@Override
//	public List<? extends ConstructorMetadata> getConstructors() {
//		 for (ClassOrInterfaceTypeDetails innerType : getMemberHoldingTypeDetails().getInnerTypes()) {
//			if(innerType.getType().getSimpleTypeName().equals(getNestedFormFieldsClassName())){
//				return innerType.getDeclaredConstructors();
//			}
//		}
//		 
//		throw new IllegalArgumentException("Inner Class "+getNestedFormFieldsClassName()+" not found.");
//	}
//	
//	public String getNestedFormFieldsClassName(){
//		return "Nested"+getGovernor().getType().getSimpleTypeName();
//	}

	@Override
	public JavaType[] getRequiredAnnotations() {
		return this.getAnnotationValues().getRequiredAnnotations();
	}

}
